using UnityEngine;

public class GetRewards : MonoBehaviour
{
	public UIEventListener claimbtn;

	public Animator animator;
	//public Animation scaleanima;

	private GameObject objui;

	private bool isshow;

	public GameObject[] itemobjs;

	public UILabel[] rewardlabels;

	public LevelBox curlevelbox;

	private bool is_one;

	private void Start()
	{
		claimbtn.onClick = OnClickclaimBtn;
	}

	public void enable(int rewardid, bool isone)
	{
		isshow = true;
		is_one = isone;
		if (objui == null)
		{
			objui = base.gameObject;
		}
		UnityVersionUtil.SetActiveRecursive(objui, state: true);
		curlevelbox = MenuDataController.instance.levelboxdata[rewardid];
		if (isone)
		{
			rewardlabels[0].text = string.Empty + curlevelbox.boxone[1].num;
			rewardlabels[1].text = string.Empty + curlevelbox.boxone[0].num;
			UnityVersionUtil.SetActiveRecursive(itemobjs[2], state: false);
			itemobjs[0].transform.localPosition = new Vector3(-50f, 0f, 0f);
			itemobjs[1].transform.localPosition = new Vector3(50f, 0f, 0f);
		}
		else
		{
			rewardlabels[0].text = string.Empty + curlevelbox.boxtwo[1].num;
			rewardlabels[1].text = string.Empty + curlevelbox.boxtwo[0].num;
			rewardlabels[2].text = string.Empty + curlevelbox.boxtwo[2].num;
			itemobjs[0].transform.localPosition = new Vector3(-90f, 0f, 0f);
			itemobjs[1].transform.localPosition = Vector3.zero;
			itemobjs[2].transform.localPosition = new Vector3(90f, 0f, 0f);
		}
		animator.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
		Invoke("playanima", Time.deltaTime * 2f);
	}

	public void playanima()
	{
		/* scaleanima["PopWinAnimation"].time = 0f;
		scaleanima["PopWinAnimation"].speed = 1f;
		scaleanima.Play(); */
		animator.SetTrigger("popWin1");
	}

	public void OnClickclaimBtn(GameObject btn)
	{
		if (isshow)
		{
			isshow = false;
			save_info();
			MonoInstance<AudioController>.instance.play(AudioType.UI_getdiamond, 0f);
			/* scaleanima["PopWinAnimation"].time = scaleanima.clip.length;
			scaleanima["PopWinAnimation"].speed = -1f;
			scaleanima.Play(); */
			animator.SetTrigger("popWin2");
			Invoke("disable", animator.runtimeAnimatorController.animationClips[0].length);
		}
	}

	public void save_info()
	{
		if (is_one)
		{
			MenuPlayerprefs.instance.AddDiamod(curlevelbox.boxone[0].num);
			MenuPlayerprefs.instance.AddMoney(curlevelbox.boxone[1].num);
		}
		else
		{
			MenuPlayerprefs.instance.AddDiamod(curlevelbox.boxtwo[0].num);
			MenuPlayerprefs.instance.AddMoney(curlevelbox.boxtwo[1].num);
			MenuPlayerprefs.instance.Addbox(curlevelbox.boxtwo[2].num);
		}
	}

	public void disable()
	{
		animator.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
		MenuBackController.instance.BackMenuUIstate();
		NGUITools.SetActive(objui, state: false);
	}
}
